package com.police.activity;

import com.police.R;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;

/**
 * 公共工具类
 * 单例模式
 * @author chenyang2
 *
 */
public class PublicTool {

	private static PublicTool publicTool;
	public ProgressDialog progressDialog;
	private static Context mContext;
	private LayoutInflater inflater;
	private RelativeLayout progressBarLayout;
	
	public static PublicTool getIntence(Context Context) {
		mContext = Context;
		if (publicTool == null) {
			publicTool = new PublicTool();
		}
		return publicTool;
	}
	
	
	public void showDialog(String message) {
		if (progressDialog == null) {
			initDialog();
		}
		progressDialog.setMessage(message);
		if (!progressDialog.isShowing()) {
			progressDialog.show();
		}
	}
	
	public void missDialog(){
		if (progressDialog != null && progressDialog.isShowing()) {
			progressDialog.dismiss();
		}
	}
	
	
	
	private void initDialog() {
		progressDialog = new ProgressDialog(mContext);
//		progressDialog.setIndeterminate(true);
//		progressDialog.setCancelable(true);
		progressDialog.setView(initProgressBarLayout());
	}
	
	/**
	 * 初始化"正在刷新"...布局
	 * @return
	 */
	public RelativeLayout initProgressBarLayout() {
		inflater = (LayoutInflater) mContext
		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		progressBarLayout = (RelativeLayout) inflater.inflate(
				R.layout.progressbar_popwindow_layout, null);
		return progressBarLayout;
	}
}
